package com.babyqiao.wallpaper.portal.controller;

import com.babyqiao.wallpaper.common.UnifyResult;
import com.babyqiao.wallpaper.portal.entity.vo.AlbumPicStatisVO;
import com.babyqiao.wallpaper.portal.service.IWallpaperAlbumPicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author QLZ
 * @date 2021/2/26
 */
@RestController
@Api(tags = "专辑图片相关接口")
@RequestMapping("/wp/albumpic")
public class ProtalAlbumPicController {
    @Autowired
    IWallpaperAlbumPicService albumPicService;

    /**
     * 修改专辑图片活跃状态,目前仅图片热度，即表中hot字段，前端最热排序根据它来排，
     * 规则：每访问一次此接口，hot即加1，不区分是否同一用户
     * 逻辑：先存redis中，定期落地到mysql中
     * */
    @PostMapping("statis/{picId}")
    @ApiOperation(value = "增加图片热度次数",httpMethod = "POST")
    public UnifyResult updateStatus(@ApiParam(name = "picId",value = "图片ID",required = true) @PathVariable String picId){
        AlbumPicStatisVO albumPicStatisVO = albumPicService.updateStatusService(picId);
        return UnifyResult.success().data("result",albumPicStatisVO);
    }

    /**
     * 点赞/取消点赞，对于表中like_it字段，前端人气排序根据他来排序
     * 规则：每个用户只能点赞一次，点赞完再点一次即为取消点赞
     * 逻辑：利用redis的bitmap实现，定期将点赞数据落地到mysql
     *
     * */

    @PostMapping("like/{picId}/{userId}/{value}")
    @ApiOperation(value = "点赞/取消点赞",httpMethod = "POST")
    public UnifyResult likeIt(@ApiParam(name = "picId",value = "图片ID",required = true) @PathVariable String picId,
                              @ApiParam(name = "userId",value = "用户ID",required = true) @PathVariable String userId,
                              @ApiParam(name = "value",value = "1->点赞，其他值->取消点赞",required = true) @PathVariable String value){
        boolean b=albumPicService.likeItService(picId,userId,value);
        return UnifyResult.success().data("result",b);
    }

    @GetMapping("likestatus/{picId}/{userId}")
    @ApiOperation(value = "获取点赞状态",httpMethod = "GET")
    public UnifyResult getLikeItStatus(@ApiParam(name = "picId",value = "图片ID",required = true) @PathVariable String picId,
                                 @ApiParam(name = "userId",value = "用户ID",required = true) @PathVariable String userId){
        Boolean status=albumPicService.getLikeItStatusService(picId,userId);
        return UnifyResult.success().data("result",status);

    }
    @GetMapping("likes/{picId}")
    @ApiOperation(value = "获取点赞总数",httpMethod = "GET")
    public UnifyResult getLikeCount(@ApiParam(name = "picId",value = "图片ID",required = true) @PathVariable String picId){
        Long count=albumPicService.getLikeCountService(picId);
        return UnifyResult.success().data("result",count);
    }

    /**
     * 修改专辑图片活跃状态,目前仅图片热度，即表中share字段。
     * 规则：分享一次就调用此接口一次，share即加1，不区分是否同一用户
     * 逻辑：先存redis中，定期落地到mysql中
     * */
    @PostMapping("share/{picId}")
    @ApiOperation(value = "增加分享数",httpMethod = "POST")
    public UnifyResult increaseShare(@ApiParam(name = "picId",value = "图片ID",required = true) @PathVariable String picId){
        AlbumPicStatisVO albumPicStatisVO=albumPicService.increShareService(picId);
        return UnifyResult.success().data("result",albumPicStatisVO);

    }
    @GetMapping("share/{picId}")
    @ApiOperation(value = "获取分享总数",httpMethod = "GET")
    public UnifyResult getShareCount(@ApiParam(name = "picId",value = "图片ID",required = true) @PathVariable String picId){
        String count=albumPicService.getShareCountService(picId);
        return UnifyResult.success().data("result",count);

    }
}
